//
//  NSDictionary+Common.m
//  BearOnLine
//
//  Created by fyanyan on 16/8/8.
//  Copyright © 2016年 fangzhou. All rights reserved.
//

#import "NSDictionary+Common.h"

@implementation NSDictionary (Common)
+ (NSString*)dictionaryToJson:(NSDictionary *)dic
{
    
    NSError *parseError = nil;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
}


+(NSDictionary *)JSONStringToNSDictionary:(NSString *)JSONString {
    if (JSONString == nil) {
        return nil;
    }
    NSData* jsonData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if (err) {
        ICLog(@"json serialize failue");
        return nil;
    }
    return dic;
}

@end
